﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Medical_Store_Billing.Data_Access_Layer;
using Medical_Store_Billing.Object_Class;
using System.Windows.Forms;

namespace Medical_Store_Billing.Business_Login_Layer
{
    class PhieunhapBLL
    {
       
        PhieunhapDAL m_phieunhapDAL=new PhieunhapDAL();
        phieunhapclass m_phieunhapclass = null;
        chitietnhapclass m_chitiet = null;

        public DataTable laychitietphieunhap(String maphieu)
        {
            return m_phieunhapDAL.Laychitietphieunhap(maphieu);
        }

 //tim phieu nhap 
        public DataTable Timphieunhap(String maphieu)
        { 
            return m_phieunhapDAL.Timphieunhap(maphieu);

        }
// load danh sach phieu nhap hang
        public DataTable Laydsphieunhap()
        {
            return m_phieunhapDAL.Laydsphieunhap();
        }



        public bool Themphieunhap(String maphieunhap, String ngaynhap,float tongtien,String manv)
        {
            try
            {
                m_phieunhapclass = new phieunhapclass();

                m_phieunhapclass.maphieunhap = maphieunhap;
                m_phieunhapclass.ngaynhap = Convert.ToDateTime(ngaynhap);
                m_phieunhapclass.tongtien = tongtien;
                m_phieunhapclass.manv = manv;

                return m_phieunhapDAL.Themphieunhap(m_phieunhapclass);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
                return false;
            }
        }

//them chi tiet phieu nhap
        public bool Themchitietphieunhap(String maphieunhap, String mahang, int soluong)
        {
            try
            {
                m_chitiet = new chitietnhapclass();

                m_chitiet.maphieunhap = maphieunhap;
                m_chitiet.mahang = mahang;
                m_chitiet.soluong = soluong;
                

                return m_phieunhapDAL.Themchitietphieunhap(m_chitiet);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
                return false;
            }
        }

        public int Demphieunhap()
        {
            DataRow r = m_phieunhapDAL.Demphieunhap().Rows[0];
            return Int32.Parse(r[0].ToString());
        }

    }


    
}
